package com.xiaohe66.web.domain.sys.sec.agg;

import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.sys.sec.value.SecEncryptId;
import com.xiaohe66.web.domain.sys.sec.value.SecEncryptPublicKey;
import com.xiaohe66.web.integration.domain.Aggregate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

import java.util.Objects;

/**
 * @author xiaohe
 * @since 2024-01-03 11:30
 */
@Builder
@Getter
@ToString
@AllArgsConstructor
public class SecEncrypt implements Aggregate<SecEncrypt, SecEncryptId> {

    @NonNull
    private final SecEncryptId id;

    @NonNull
    private final AccountId createId;

    private SecEncryptPublicKey publicKey;

    public SecEncryptPublicKey changePublicKey(SecEncryptPublicKey publicKey) {
        SecEncryptPublicKey old = this.publicKey;
        this.publicKey = publicKey;
        return old;
    }

    @Override
    public boolean hasSameRootAttribute(SecEncrypt other) {
        return other != null &&
                Objects.equals(publicKey, other.publicKey);
    }
}
